package org.ourgrid.broker.business.schedulerdata.executor;

import java.util.ArrayList;
import java.util.List;

import org.ourgrid.broker.business.schedulerdata.SchedulerData;
import org.ourgrid.common.internal.IResponseTO;
import org.ourgrid.common.internal.response.ReleaseResponseTO;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class ReleaseWorkerExecutor extends AbstractSchedulerDataExecutor {
	
	/**
	 * <RELEASE_WORKER workerID='String'/>
	 */
	public List<IResponseTO> execute(SchedulerData command) {
		List<IResponseTO> responses = new ArrayList<IResponseTO>();
		
		Document logDocFile = super.getXMl(command.getXml());
		
		Element element = logDocFile.getDocumentElement();
		
		String wID = element.getAttribute("workerID");
		
		if (wID != null) {
			ReleaseResponseTO responseTO = new ReleaseResponseTO();
			responseTO.setStubAddress(getAddress(wID));
			responses.add(responseTO);
		}	
		
		return responses;
	}
}
